
import java.util.ArrayList;
import java.util.List;
//杨辉三角
public class Test {
    public List<List<Integer>> generate(int numRows) {
        List<List<Integer>> ret = new ArrayList<>();
        List<Integer> row = new ArrayList<>();
        row.add(1);
        ret.add(row);
        for (int i = 1; i < numRows; i++) {
            List<Integer> preRow = ret.get(i-1);//前一行
            List<Integer> curRow = new ArrayList<>();
            curRow.add(1);//第一个1
            //中间curRow list的赋值
            for (int j = 1; j < i; j++) {
                int x = preRow.get(j) + preRow.get(j-1);
                curRow.add(x);
            }
            curRow.add(1);//最后一个1
            ret.add(curRow);
        }
        return ret;
    }

    public static void main(String[] args) {
        Test test = new Test();
        List<List<Integer>> ret = new ArrayList<>();
        ret = test.generate(5);
        for (List<Integer> integer : ret) {
            System.out.println(integer + " ");
        }
    }

}
